-- AvalonCannon
-- Created by dengc Sep/20/2016
-- 阿瓦隆巨炮格子

require "game/ui/form/dungeon/special/UIAvalonCannonMain"

-- 初始化
function initAvalonCannon(self, launchFunc)
    local classId = self.gridData.class_id;
    local avalonCannon = self.gridData.avalon_cannon;
    local pos = self.gridData:getPos();

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            -- 打开界面
            local uiForm = UIAvalonCannonMain.create(classId, pos);
            UIMgr.getCurrentScene():addForm(uiForm);

            -- 音效
            AudioM.playFx("equip_unload");
        end
    end

    local iconPath = getLevelItemIconPath("avalon_cannon");
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.icon:setOpacity(0);
    self.item:addChild(self.icon);
end

-- 阿瓦隆巨炮被摧毁
function playCannonDestoryEffect(self)
    -- 建筑爆炸效果
    local effectParent = UIDungeonMgr:getCurLevel():getEffectParent();
    local node = effectParent:getChildByName("avalonCannon");
    playNodeDisappear(self, node);

    -- 建筑消失
    playBuildingDisappear2(self);
end
